package cn.dnui_yxk801.dnuifood_16110100801.controller;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import java.util.List;

import cn.dnui_yxk801.dnuifood_16110100801.R;
import cn.dnui_yxk801.dnuifood_16110100801.bean.CollectBean;
import cn.dnui_yxk801.dnuifood_16110100801.bean.ResultBean;
import cn.dnui_yxk801.dnuifood_16110100801.bean.UserBean;
import cn.dnui_yxk801.dnuifood_16110100801.listener.OnRetrofitListener;
import cn.dnui_yxk801.dnuifood_16110100801.model.UserModel;

public class RegisterActivity extends BaseActivity implements View.OnClickListener,OnRetrofitListener<ResultBean>{

    private UserModel model;
    private Button button;
    private EditText etname;
    private EditText etpass;
    private EditText etnum;
    private EditText etadd;
    private EditText etjj;
    protected void onCreate(Bundle savedInstanceState) {
        Intent i=getIntent();
        super.onCreate(savedInstanceState);
//        setContentView(R.layout.activity_register);
    }
    @Override
    void initViews() {
        layout_file=R.layout.activity_register;
        setLayout(layout_file);
        button=findViewById(R.id.button);
        etname=findViewById(R.id.etname);
        etpass=findViewById(R.id.etpass);
        etnum=findViewById(R.id.etnum);
        etadd=findViewById(R.id.etadd);
        etjj=findViewById(R.id.etjj);
    }

    @Override
    void initEvents() {
        button.setOnClickListener(this);
    }

    @Override
    void initDatas() {

    }


    @Override
    public void onClick(View view) {
        String username=etname.getText().toString();
        String userpass=etpass.getText().toString();
        String mobilenum=etnum.getText().toString();
        String address=etadd.getText().toString();
        String comment=etjj.getText().toString();
        model=new UserModel();
        model.register(username,userpass,mobilenum,address,comment,this);

    }



    @Override
    public void onSuccess(ResultBean object, int flag) {
        Toast.makeText(RegisterActivity.this,"注册成功",Toast.LENGTH_SHORT).show();
        Intent i =new Intent(RegisterActivity.this,LoginActivity.class);
        startActivity(i);
    }



    @Override
    public void onFalure(String msg) {
        Toast.makeText(RegisterActivity.this,"注册失败",Toast.LENGTH_SHORT).show();
    }
}
